<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>请输入支付金额</title>
<script type="text/javascript" src="${base }/static/jquery.min.js"></script>
</head>
<body>
	<form id="form">
		<input type="hidden" name="openId" value="${openId }" /> <input type="hidden" name="mercId" value="${mercId }" /> <input type="hidden" name="body" value="${body }" />
		<div style="height: 20em; width: 100%;">支付信息：</div>
		<div>
			<input type="text" name="txnAmt" style="width: 100%; height: 4em; border: 1px solid #DDD; font-size: 2em; text-align: center;" placeholder="请输入支付金额" />
		</div>
		<div style="text-align: center; margin-top: 5em;">
			<button type="button" style="width: 40em; height: 8em; font-size: 2em;" onclick="pay()">立即支付</button>
		</div>
	</form>
	<script type="text/javascript">
		function pay() {
			var form = $("#form").serializeArray();
			$.post("${base}/channel/P00201", form, function(data) {
				if (data.jsapi) {
					onBridgeReady(data.jsapi);
				} else {
					alert(data);
				}
			}, "json");
		}
		function onBridgeReady(p) {
			WeixinJSBridge.invoke('getBrandWCPayRequest', p, function(res) {
				if (res.err_msg == "get_brand_wcpay_request：ok") {
					alert(res.err_msg);
				} // 使用以上方式判断前端返回,微信团队郑重提示：res.err_msg将在用户支付成功后返回    ok，但并不保证它绝对可靠。 
				else {
					alert(res.err_msg);
				}
			});
		}
		/* if (typeof WeixinJSBridge == "undefined") {
			if (document.addEventListener) {
				document.addEventListener('WeixinJSBridgeReady', onBridgeReady,
						false);
			} else if (document.attachEvent) {
				document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
				document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
			}
			alert(typeof WeixinJSBridge);
		} else {
			//onBridgeReady();
		} */
	</script>
</body>
</html>